//
//  ThirtythreeViewController.m
//  Depressed.domo
//
//  Created by rimi on 16/5/27.
//  Copyright © 2016年 薛涛. All rights reserved.
//

#import "ThirtythreeViewController.h"
#import "BQActivityView.h"
@interface ThirtythreeViewController ()
@property (nonatomic, strong) CAReplicatorLayer *reaplicator;
@end

@implementation ThirtythreeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor cyanColor];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CRM(200,400 , 100, 50);
    button.backgroundColor = [UIColor redColor];
    [button addTarget:self action:@selector(xxxx:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}
- (void)xxxx:(UIButton *)sender{
    [BQActivityView showActiviTy];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [BQActivityView hideActiviTy];
    });
}

- (CAReplicatorLayer *)reaplicator{
    if (_reaplicator == nil) {
        //需要实例化的个数
        int numofInstance = 10;
        //动画时长
        CGFloat duration = 1.0f;
        //创建repelicator对象
        CAReplicatorLayer *repelicator = [CAReplicatorLayer layer];
        //设置其位置
        repelicator.frame = self.view.bounds;
        //需要生成多少个相同实例
        repelicator.instanceCount = numofInstance;
        //代表实例生成的延时时间;
        repelicator.instanceDelay = duration / numofInstance;
        //设置每个实例的变换样式
        repelicator.instanceTransform = CATransform3DMakeRotation(M_PI * 2.0 / 10.0, 0, 0, 1);
        
        //创建repelicator对象的子图层，repelicator会利用此子图层进行高效复制。并绘制到自身图层上
        CALayer *layer = [CALayer layer];
        //设置子图层的大小位置
        layer.frame = CGRectMake(0, 0, 10, 10);
        //子图层的仿射变换是基于repelicator图层的锚点，因此这里将子图层的位置摆放到此锚点附近。
        CGPoint point = [repelicator convertPoint:repelicator.position fromLayer:self.view.layer];
        layer.position = CGPointMake(point.x, point.y - 20);
        //设置子图层的背景色
        layer.backgroundColor = [UIColor whiteColor].CGColor;
        //将子图层切圆
        layer.cornerRadius = 5;
        
        //将子图层添加到repelicator上
        [repelicator addSublayer:layer];
        //对layer进行动画设置
        CABasicAnimation *animaiton = [CABasicAnimation animation];
        //设置动画所关联的路径属性
        animaiton.keyPath = @"transform.scale";
        //设置动画起始和终结的动画值
        animaiton.fromValue = @(1);
        animaiton.toValue = @(0.1);
        //设置动画时间
        animaiton.duration = duration;
        //设置动画次数
        animaiton.repeatCount = INT_MAX;
        //添加动画
        [layer addAnimation:animaiton forKey:nil];
        
        _reaplicator = repelicator;
    }
    return _reaplicator;
}
@end
